<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<script type="text/javascript">
	var dataAuthObjectDataGrid = $('#dataAuthObject-datagrid-json').datagrid({
		gridTitle : '数据权限对象管理',
	    showToolbar: true,
	    toolbarItem: '',
	    addLocation: 'first',
	    showLinenumber: false,
	    filterThead: false,
	    filterAll: true,
	    sortAll : true,
	    dataUrl: 'dataAuthObject/list.do',
	    dataType: 'json',
	    columns: [
	        {
				name: '',
				label: '操作',
				align: 'center',
				width: 140,
				quicksort:false,
				menu: false,
				edit: false,
				render: function(value){
			        var html = '';
			    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-blue btn-sm" onclick="editMmDataAuthObject(this)"><i class="fa fa-edit"></i> 编辑</button></div>';
				    html += '<div class="btn-group" role="group"><button type="button" class="btn btn-red btn-sm" onclick="delMmDataAuthObject(this)"><i class="fa fa-remove"></i> 删除</button></div>';
				    return html;
				}
	        },
	        
	        {
	            name: 'objectName',
	            label: '对象名称',
	            align: 'center',
	            width: 200
	        },
	        
	        {
	            name: 'objectValue',
	            label: '对象值',
	            align: 'center',
	            width: 300
	        },
	        
	        {
	            name: 'valueType',
	            label: '对象值类型',
	            type : 'select',
	            items:[
	            	{'ID':'ID'},
	            	{'NAME':'名称'}
	            ],
	            align: 'center',
	            width: 120,
	            render: $.datagrid.renderItem
	        }

	    ],
	    afterSave: function($trs, datas) {
	        	this.refresh();
	        },
	    paging: {pageSize:20, selectPageSize:'20,30,40'},
	    showTfoot: true,
	    fullGrid: false,
	    toolbarCustom: function(){
	    	var html = '';
	    	html += '<div class="btn-group" role="group"><button type="button" class="btn btn-blue" onclick="addMmDataAuthObject()"><i class="fa fa-plus"></i> 添加</button></div>';
		    html += '<div class="btn-group" role="group"><button type="button" class="btn btn-green" onclick="refreshMmDataAuthObject()"><i class="fa fa-refresh"></i> 刷新</button></div>';
		    return html;
	    }
	});
	try {
		dataAuthObjectDataGrid.data('bjui.datagrid').colLock(0, true);
	} catch (e) {}
	
	function refreshMmDataAuthObject() {
		dataAuthObjectDataGrid.datagrid("refresh");
	}

	function addMmDataAuthObject() {
		$('#edit-dataAuthObject-dialog').dialog({
			id:'add-dataAuthObject-dialog', 
			url:'dataAuthObject/add.do', 
			maxable: false,
			mask: true,
			width: 850,
			height: 300,
			onLoad: function($dialog){
				setEditMmDataAuthObjectBtnEvent($dialog, true);
			},
			title:'数据权限对象管理 - 添加'});
	}
	function editMmDataAuthObject(_this) {
		var index = $(_this).closest("tr").index();
		var data = dataAuthObjectDataGrid.data('bjui.datagrid').getRowData(index);
		$('#edit-dataAuthObject-dialog').dialog({
			id:'edit-dataAuthObject-dialog',
			url:'dataAuthObject/edit.do',
			maxable: false,
			mask: true,
			width: 850,
			height: 300,
			onLoad: function($dialog){
				setEditMmDataAuthObjectBtnEvent($dialog, false);
				getJsonData2Form('dataAuthObject/get.do', 'id='+data.id, $('#dataAuthObject_form'), dataAuthObjectCallback);
			},
			
			title:'数据权限对象管理 - 编辑'});
	}
	function delMmDataAuthObject(_btn){
		var index = $(_btn).closest("tr").index();
		var data = dataAuthObjectDataGrid.data('bjui.datagrid').getRowData(index);

		dataAuthObjectDataGrid.alertmsg('confirm', '确定删除当前数据？', 
			{
			    displayMode:'slide', 
	            okName:'确定', 
	            cancelName:'取消', 
	            title:'提示信息',
	            okCall : function(){
	            	var url = "dataAuthObject/del.do?id="+data.id;
					var successCallBack = function(){
						refreshMmDataAuthObject();
					}
					myAjax(url,	null, null,successCallBack,null);
	            }
	    });
	}
	
	function dataAuthObjectCallback($inputObj, _name, _val){
		
	}
	
	function setEditMmDataAuthObjectBtnEvent($dialog, isAdd) {
		var $save, $cancel;
		$save = $dialog.find('.save');
		$cancel = $dialog.find('.cancel');
	
		$save.click(function(){
			$('#dataAuthObject_form').isValid(function(v) {
				if(v){
					var url = 'dataAuthObject/addSave.do';
					if (!isAdd) {
						url = 'dataAuthObject/editSave.do';
					}
					var data = $('#dataAuthObject_form').serialize();
					var successCallBack = function(){
						$dialog.dialog('closeCurrent');
						refreshMmDataAuthObject();
					}
					myAjax(url,	data, true,successCallBack,null);
				}
			});
		});
	
		$cancel.click(function(){
			$dialog.dialog('closeCurrent');
		});
	}
</script>
<div class="bjui-pageContent" id="dataAuthObject-index-pagecontent">
    <div style="padding:0px; height:100%; width:100%;">
        <table id="dataAuthObject-datagrid-json" data-width="100%" data-height="100%" class="table table-bordered">
        </table>
    </div>
</div>
<div id="edit-dataAuthObject-dialog" style="display: none;">
</div>